package edu.sias.controller;
import edu.sias.pojo.S_User;

import edu.sias.service.UserService;



import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;



@WebServlet(urlPatterns = "/validateName")

public class ValidateServlet extends HttpServlet {



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {



        //获取用户注册时输入的用户名

        String name = request.getParameter("name");

        UserService userService = new UserService();

        //调用业务层中的操作，根据用户名查找用户信息

        S_User user = userService.findUserInfoByName(name);

        if (null != user){

            //用户名校验失败

            //异步 操作中，需要将返回的数据封装到response中

            response.getWriter().write("账号已存在，请输入新的账号");

        }else {

            //用户名校验成功

            response.getWriter().write("当前用户名可用");

        }







    }

}
